<style scoped>
	article{
		margin-bottom:50px;
	}
	.article-title{
		margin-top:50px;
		text-align:center;
	}

	.article-info {
		text-align: center;
		margin-top:7px;
		margin-bottom:20px;
		font-size:12px;
		color:#888;
	}
	.article-info > span:nth-of-type(1){
		margin-right:5px;
	}
	.article-info > i:nth-of-type(2){
		margin-left:5px;
	}
</style>


<template>
	<div id='postid' :key='article.id'>
			<article>
				<h1 class='article-title' v-text='article.title'></h1>
				<div class='article-info'>
					<Icon type="ios-calendar-outline"></Icon>
					 发表于 
					<span v-text='article.publishTime'></span>
					  |  
					<Icon type="ios-eye-outline"></Icon>
					 阅读数 
					<span v-text='article.readingAmount'></span>
				</div>
				<div v-html='article.html' class='markdown-body'></div>
			</article>
		<Button type="info" @click='modify'>修改</Button>
    	<Button type="error" @click='del'>删除</Button>
	</div>
</template>


<script>
export default {
        name: 'Postid',
        data () {
            return {
				article:{

				},
            }
        },
        mounted() {
        	this.$Loading.start();//加载动画开始
			const that = this;
            this.$http.get(
            	that.surl+that.$route.path.substring(7)+'?sessionID='+that.$cookie.get('sessionID')
            )
              .then(function (response) {
              	that.$Loading.finish();//加载完毕
              	if(response.data!==false){
				  that.article = response.data;
              	}else{
              		that.$router.push('/admin/404');
              	}
              })
              .catch(function (error) {
				/*that.$router.push('/404');*/
              });
        },
        methods:{
        	modify(){
        		this.$router.push('/admin/home/modify/'+this.article._id);
        	},
        	del(){
	        	this.$Modal.confirm({
	                title: '确认删除',
	                content: '<p>删除 <strong>'+this.article.title+'</strong> ?</p>',
	                loading: true,
	                onOk: () => {
	                	const that = this;
                        this.$http.get(
					        	that.surl+'deletearticle?sessionID='+that.$cookie.get('sessionID')+'&_id='+that.article._id
					        )
				            .then(function (response) {
				          		if(response.data===true){
									that.$Modal.remove();
                            		that.$Message.success('删除成功');
                            		that.$router.push('/admin/home');
				          		}else{
									that.$Modal.remove();
                            		that.$Message.error('删除失败');
				          		}
				            })
					        .catch(function (error) {
					            that.$Modal.remove();
                            	that.$Message.error('删除失败');
					        });
					}
	            });        		
        	}
        }
    }
</script>